<?php
/*

file version 2005-06-09 15:17:50

*/
wakNeedClass('mvcinterface');

class users extends mvcInterface {
/*--------------------------------------------------------------------------------------------------
                                                                                         constructor
--------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------
                                                                                      public methods
--------------------------------------------------------------------------------------------------*/
	/*
	*/
	function insertform() {
		return $this->getFedView('insertform');
	}
	
	function editform($p=array()) {
		if (!isset($p['id'])) return false;
		$this->data->set('/params/id',$p['id']);
		$this->importUniqueResult('getone','/user','/params');
		//echo wakAffvar($this->data->get(),'data');
		//$data=$this->data->get('/user');
		//echo wakAffvar($data,'data');
		return $this->getFedView('editform','/user');
	}
	
	function edit() {
		// importing and validating post data
		if (!$this->importValidPost('updateKeys','/toupdate')) {
			// return false;
			$this->data->set('/updated',false);
		} else {
			// echo wakaffvar($this->data->get());
			// if new pwd provided, md5 crypting
			if ($this->data->get('/toupdate/newpwd'))
				$this->data->applyFunction('/toupdate/newpwd','md5');
			// sql securing
			$this->secureValues('/toupdate/*');
			// execution
			$this->runQuery('update','/toupdate','/updated');
		}
		//echo wakaffvar($this->data->get(),'/');
		// returning view
		return $this->getFedView('updated');
	}
	
	/*
	*/
	function insert() {
		// importing and validating post data
		if (!$this->importValidPost('insertKeys','/toinsert')) {
			$this->data->set('/inserted',false);
			//return false;
		} else {
			// cryptage md5 du mot de passe
			$this->data->applyFunction('/toinsert/pwd','md5');
			// securisation SQL
			$this->secureValues('/toinsert/*');
			// execution
			$this->runQuery('insert','/toinsert','/inserted');
		}
		// returning view
		return $this->getFedView('inserted');
	}
	
	function getlist() {
		$this->importResult('list','/users');
		return $this->getFedView('list');
	}
	
	/*function getById($id) {
	
	}
	
	function getByLoginPwd($login,$pwd) {
	
	}*/
/*--------------------------------------------------------------------------------------------------
                                                                                          properties
--------------------------------------------------------------------------------------------------*/
	//var //
/*--------------------------------------------------------------------------------------------------
                                                                                     private methods
--------------------------------------------------------------------------------------------------*/
	/*
	*/
	/*function () {

	}*/
}
?>
